*Code to replicate results of "Incumbency Advantage: Price Dispersion, Price Discrimination and Consumer Search at Online Platforms", 2023, forthcoming at JPE Micro

set more off, permanently
version 14
set linesize 80

cd "C:\Users\sheim\Dropbox\GHJL"

******************************
*
* 1. Construction of dataset
*
******************************

// Price data (e'net)

* construct dataset set on cheapest entrant tariffs
* source file data at the monthly level

import delimited "HH_3500_kWh_NEU.csv", clear delimiter(";") encoding(UTF-8)

gen time=substr(stichtag,1,10)
gen date=date(time, "YMD")
format date %td
gen month=month(date)
gen year=year(date)

foreach var of varlist ///	
	netz_tarif_ap netz_tarif_gp netz_tarif_mess ka kwk_aufschlag ///
	strom_sonderkundenumlage offshore_haftungsumlage abschalt_umlage eeg_umlage stromsteuer  ///
	abgaben_steuern_gesamt ap gp gesamtpreis_tarif summe_nne_steuer_abgaben rohmarge ///
	windkraft_prozent solarenergie_prozent wasserkraft_prozent erneuerbare_prozent ///
	fossile_prozent kernkraft_prozent sonstige_prozent co2_ausstoss atommuell biomasse_prozent kwk_prozent ///
{
	qui destring `var', replace dpcomma
}

collapse (max) gemeindekennziffer evu_nr netz_nr haupt_grundversorger (mean) ee* netz_tarif_mess rohmarge gesamtpreis_tarif ap gp ka netz_tarif_gp netz_tarif_ap kwk_aufschlag stromsteuer abgaben_steuern_gesamt einwohner verbrauch, by(year plz)

save  "cheapest_overall.dta", replace

* construct dataset set on incumbent baseline tariffs
* source file data at the monthly level

import delimited GV_HH_3500_kwh_NEU.csv, clear delimiter(";") encoding(UTF-8)

gen time=substr(stichtag,1,10)
gen date=date(time, "YMD")
format date %td
gen month=month(date)
gen year=year(date)

rename gesamtpreis_tarif gesamtpreis_tarif_gv
rename rohmarge rohmarge_gv
rename evu_status evu_status_gv
rename ap ap_gv
rename gp gp_gv
rename netz_nr netz_nr_gv
rename haupt_grundversorger haupt_grundversorger_gv
rename netz_tarif_mess netz_tarif_mess_gv
rename evu_nr evu_nr_gv

foreach var of varlist ///
	netz_tarif_ap netz_tarif_gp netz_tarif_mess ka kwk_aufschlag strom_sonderkundenumlage ///
	offshore_haftungsumlage abschalt_umlage eeg_umlage stromsteuer abgaben_steuern_gesamt ap gp ///
	gesamtpreis_tarif summe_nne_steuer_abgaben rohmarge windkraft_prozent solarenergie_prozent ///
	wasserkraft_prozent erneuerbare_prozent fossile_prozent kernkraft_prozent sonstige_prozent ///
	co2_ausstoss atommuell biomasse_prozent kwk_prozent ///
{
	qui destring `var', replace dpcomma
}

collapse (max) gemeindekennziffer evu_nr_gv netz_nr_gv haupt_grundversorger_gv (mean) eeg netz_tarif_mess_gv rohmarge_gv gesamtpreis_tarif_gv ap_gv gp_gv ka netz_tarif_gp netz_tarif_ap kwk_aufschlag stromsteuer abgaben_steuern_gesamt einwohner verbrauch, by(year plz)

save  "incumbent_base.dta", replace

* construct dataset set on incumbent baseline tariffs
* source file data at the yearly level

import delimited using "BGV_HH_3500_kWh.csv", clear delimiter(";")
rename jahr year
rename gesamtpreis_tarif price_incumbent_cheap
rename rohmarge rohmarge_incumbent_cheap
save "incumbent_cheap.dta", replace

* merge incumbent baseline tariffs, entrant tariffs and incumbent cheap tariffs
use "incumbent_base.dta", clear

merge 1:1 year plz using "incumbent_cheap.dta", keepusing(price_incumbent_cheap rohmarge_incumbent_cheap evu_nr_gv)
drop if _merge!=3
drop _merge

merge 1:1 plz year using "cheapest_overall.dta"
drop _merge

save "prices.dta", replace

* generate dataset indicating overlap of incumbency areas within a zip code

import excel "2012_PLZ_ORT_Haupt_GV_weitere_GV.xlsx", clear sheet("Tabelle1") firstrow case(lower) clear
collapse (max) weitere_grundversorger,by(plz)
save "multiple_inc.dta", replace
 
* socio-economic data (Acxiom)

import excel "ZEW_Liefer_2009-2014_neu.xls", clear sheet("2009_2014") firstrow case(lower)

rename 	jahr year
rename 	prikeuro purch_power
rename 	bv_to population_total
rename 	ph_to num_hh
gen 	hh_size=population_total/num_hh

destring plz, replace

save "acxiom.dta", replace

// search queries elecricity

import delimited "wbs_csv_windows_1252_tb_Anfragen.csv", clear delimiter(";") encoding(UTF-8)

keep enet_session_id anfrage_zeitpunkt anfrage_reihenfolge plz ort kdgruppentyp_typ mm_oeko

// only keep queries for private tariffs (exclude queries for business tariffs)
keep if kdgruppentyp_typ=="P"
drop kdgruppentyp_typ

gen time=substr(anfrage_zeitpunkt, 1,10)
gen date = date(time, "DMY")
format date %td
gen year=year(date)
gen month=month(date)
gen week=week(date)
gen day=day(date)

*drop if session_id==.
drop if ort==""
drop if anfrage_reihenfolge>1

gen search_electricity=1

save "search_electricity_prep.dta",replace

collapse (sum) search_electricity mm_oeko, by(plz year)

save "search_electricity_final.dta", replace

// search queries gas

*  data on gas searches have been delivered as four csv files by ene't, one for each year.
*  2011 has variable names in the first row, 2012-2014 not.

* Import csv file for 2011
import delimited "WSB__keiner_31.12.2011.csv", delimiter(";") encoding(UTF-8)

* only keep relevant variables
keep enetsessionid timestamp kz_energieart plz ort kz_kundengruppe kz_oeko 
keep if kz_energieart=="G"

* save as dta
save "search_data_gas_2011.dta", replace

* import csv file for 2012-2014
clear

forval i= 2012(1)2014{
	preserve
	clear
	import delimited using WSB_`i'.csv, delimiter(";") varnames(nonames) encoding(UTF-8) 

	// rename columns to match with the 2011 data
	rename v1 id
	rename v2 satz
	rename v3 file_id
	rename v4 lieferant_id
	rename v5 datum_erstellung
	rename v6 enetsessionid
	rename v7 herkunft
	rename v8 timestamp
	rename v9 kz_energieart
	rename v10 plz
	rename v11 ort
	rename v12 kz_kundengruppe
	rename v13 verbrauch
	rename v14 leistung
	rename v15 kz_vorauskasse
	rename v16 kz_kaution
	rename v17 kz_preisgarantie
	rename v18 preisgarantiemonate
	rename v19 kz_bonus
	rename v20 kz_oeko
	rename v21 kz_empfohlen
	rename v22 kz_anmeldung
	rename v23 kz_hauptzeit
	rename v24 maxlaufzeit
	rename v25 anz_tarif
	rename v26 kuendigungsfrist
	rename v27 zahlungsweise
	rename v28 ausgabe
	rename v29 session
	rename v30 reihenfolgeanfrage
	rename v31 page
	rename v32 pagetype
	rename v33 gvu_nr
	rename v34 gvu_name
	rename v35 gvu_pid
	rename v36 gvu_preis
	rename v37 gvu_pos 
	rename v38 vu_top
	rename v39 vu_top_name
	rename v40 pid_top
	rename v41 pid_top_name
	rename v42 sid_top
	rename v43 preis_top
	rename v44 vu_nr_vg
	rename v45 vu_name_vg
	rename v46 pid_vg
	rename v47 pid_name_vg
	rename v48 sid_vg
	rename v49 pos_vg
	rename v50 preis_vg

	// only keep relevant variables
	keep enetsessionid timestamp kz_energieart plz ort kz_kundengruppe kz_oeko 
	keep if kz_energieart=="G"
	
	// save as dta
	save search_data_gas_`i'.dta, replace
	restore
}


use "search_data_gas_2011.dta",clear

forval i=2012(1)2014{

	append using "search_data_gas"_`i'.dta
	save "search_data_gas_all.dta", replace
}


gen time=substr(timestamp, 1,10)
gen date = date(time, "YMD")
format date %td
gen year=year(date)
gen month=month(date)
gen day=day(date)

* session IDs are given multiple times, define real search session ID 
egen session_id=group(plz ort day month year enetsessionid)
sort session_id date

* keep one observation per session
by session_id (date): gen x=(_n==1)
keep if x==1
collapse (sum) x, by(plz year)
rename x search_gas

save "search_gas_final.dta", replace


// Merge price data with search data and socio-economic data

use "prices.dta", clear

merge 1:1 plz year using "acxiom.dta"
drop _merge

merge 1:1 plz year using "search_gas_final.dta"
drop _merge


keep if year==2011|year==2012|year==2013|year==2014

merge 1:1 plz year using "search_electricity_final.dta"
drop _merge


// compute search intensity for electricity and gas

* remove searches for green tariffs
replace search_electricity=search_electricity-mm_oeko

* Give zip codes without search queries zero queries
replace search_electricity	=0 if search_electricity==.
replace search_gas			=0 if search_gas==. 

* search intensity as ratio of search queries and number of households in a zip code-year pair
replace search_electricity	=search_electricity/num_hh*100
replace search_gas			=search_gas/num_hh*100

* remove "bot searches"
pctrim search_electricity,	p(0 98) recode(miss) replace 
pctrim search_gas,			p(0 99) recode(miss) replace 

gen search_electricity_sq=search_electricity^2

* adjust for for 19% VAT
replace gesamtpreis_tarif_gv=gesamtpreis_tarif_gv*1.19
rename gesamtpreis_tarif_gv price_incumbent_base

replace gesamtpreis_tarif=gesamtpreis_tarif*1.19
rename gesamtpreis_tarif cheapest_overall

replace price_incumbent_cheap=price_incumbent_cheap*1.19

// Figure 4                                          *

* ssc install spmap

gen PLZ99_N=plz
merge n:1 PLZ99_N using plzmatch, keep(match master)
drop _merge
gen gains_from_search=price_incumbent_base-cheapest_overall
xtset plz year

spmap gains using plzkoord.dta if year==2012, id(id) fcolor(Blues) osize(vvthin vvthin vvthin vvthin vvthin) ndsize(vvthin)
graph export "gains_from_search.dta", replace

* drop missing prices
drop if price_incumbent_base==.
drop if price_incumbent_cheap==.
drop if cheapest_overall==.


foreach var in price_incumbent_base price_incumbent_cheap cheapest_overall ///
{
	replace `var'=round(`var', 0.01)
}

// Manually generating variable on EEX wholesale electricity price (EEX Base Future 1-year ahead)

* wholesale electricity prices
gen bfut=56.07 if year==2011
replace bfut=49.30 if year==2012
replace bfut=39.08 if year==2013
replace bfut=35.09 if year==2014

* gen price dispersion and price discrimination variables
gen double price_dispersion=price_incumbent_base-cheapest_overall
gen double online_price_dispersion=price_incumbent_cheap-cheapest_overall
gen double price_discrimination=price_incumbent_base-price_incumbent_base


* gen markups
gen double rm_inc=rohmarge_gv-bfut*3.5
gen double rm_ent=rohmarge-bfut*3.5
gen double rm_cheapest_gv=rohmarge_incumbent_cheap-bfut*3.5

gen net_costs=price_incumbent_base/1.19-rm_inc

* drop zip codes with more than one incumbent
merge m:1 plz using "multiple_inc.dta"
drop _merge
drop if evu_nr_gv==.
drop if weitere==1


* define price zone
egen price_zone=group(price_incumbent_base price_incumbent_cheap cheapest_overall evu_nr_gv)

* compute average purchasing power per houehold in 1000 Euro
replace purch_power=purch_power/1000/num_hh


* compute Hausman-style instruments

gen plz_string	= string(plz,"%05.0f")
gen plz_4dig	= substr(plz_string,1,4)

foreach var in search_gas search_electricity {

	egen count1_`var'	= count(`var')	,by(plz_4dig year)
	egen count2_`var'	= count(`var')	,by(plz_4dig year price_zone)
	
	egen sum1_`var'		= sum(`var')	,by(plz_4dig year)
	egen sum2_`var'		= sum(`var')	,by(plz_4dig year price_zone)

	gen `var'_haus=(sum1_`var'-sum2_`var')/(count1_`var'-count2_`var')
}

* log transformation

foreach var in search_gas_haus search_electricity_haus search_electricity search_gas  price_incumbent_base price_incumbent_cheap cheapest_overall price_dispersion price_discrimination online_price_dispersion net_costs num_hh hh_size purch{
		gen log_`var'=log(`var') 
		sum `var' if `var'!=0,d
		replace log_`var'=log(r(min)) if `var'==0
}

* label variables

label var price_incumbent_base "Incumbent Base ($ P^{I}_{H}$)"
label var cheapest_overall "Overall Cheapest ($ P^{E}$)"
label var price_incumbent_cheap "Incumbent Cheapest ($ P^{I}_{L}$)"
label var price_dispersion "Price Dispersion ($ P_{H}^{I} - P^{E}$)"
label var online_price_dispersion "Online Price Dispersion ($ P_{L}^{I} - P^{E}$)"
label var price_discrimination "Price Discrimination ($ P_{H}^{I} - P_{L}^{I}$)"

label var log_price_incumbent_base "Incumbent Base ($ P^{I}_{H}$)"
label var log_cheapest_overall "Overall Cheapest ($ P^{E}$)"
label var log_price_incumbent_cheap "Incumbent Cheapest ($ P^{I}_{L}$)"
label var log_price_dispersion "Price Dispersion ($ P_{H}^{I} - P^{E}$)"
label var log_online_price_dispersion "Online Price Dispersion ($ P_{L}^{I} - P^{E}$)"
label var log_price_discrimination "Price Discrimination ($ P_{H}^{I} - P_{L}^{I}$)"

label var search_electricity "Search ($\mu$)"
label var search_electricity_sq "Search^2"
label var log_search_electricity "Search ($\mu$)"

label var search_gas "Searches for gas tariffs"
label var log_search_gas "Searches for gas tariffs"

label var num_hh "No. households"
label var log_num_hh "No. households"
label var hh_size "Household size"
label var log_hh_size "Household size"
label var purch "Available income"
label var log_purch "Available income"

label var net_costs "Costs"
label var log_net_costs "Costs"


* make globals for estimations

global price_controls =" log_net_costs log_purch log_num_hh log_hh_size"
global instr="log_search_gas"

global options_ols 	= "absorb(plz year) cluster(plz) robust"
global options_iv 	= "absorb(plz year) cluster(plz) robust endogtest(log_search_electricity)"


// Figure 2

preserve
	gen net_price_incumbent_base=price_incumbent_base/1.19
	gen net_price_incumbent_cheap=price_incumbent_cheap/1.19
	gen net_cheapest_overall=cheapest_overall/1.19

	collapse (mean) net_costs net_price_incumbent_base net_price_incumbent_cheap net_cheapest_overall,by(year)
	
	label var net_price_incumbent_base "Incumbent Base ($ P^{I}_{H}$)"
	label var net_price_incumbent_cheap "Incumbent Cheapest ($ P^{I}_{L}$)"
	label var net_cheapest_overall "Overall Cheapest ($ P^{E}$)"
	label var net_costs "Costs"
	twoway (line net_price_incumbent_base year, lc(black) lp(solid))(line net_price_incumbent_cheap year, lc(black) lp(dot))(line net_cheapest_overall year, lc(black) lp(dash)) (line net_costs year,lc(black) lp(dash_dot)), ytitle("€/year for 3.500 kWh consumption",margin(large))
	graph export "figure2.png", replace
restore

// Figure 6

* left panel (use data set search_electricity_prep which was constructed earlier in the code)
use "search_electricity_prep.dta",clear

sort year month week
collapse (sum) search_electricity,by(year month week)
egen date=group(year month week)
twoway line search_electricity date, xline(36 98 157 218)
graph export weekly_searches.png

* right panel
import delimited "multiTimeline.csv", clear delimiter("") varnames(2)
gen year=substr(monat,1,4)
gen month=substr(monat,6,.)
destring year month, replace
egen date=group(year month)
drop if year>2014
collapse (sum) strompreisvergleich, by(date)
twoway line strompreisvergleich date, xline(8 20 32 44)
graph export google_trends.png, replace

***************************
*	2. Summary statistics
***************************

// Table 1

* drop singletons
xtset plz year
ivreghdfe log_price_incumbent_base $price_controls (log_search_electricity=$instr),  absorb(plz year) 
keep if e(sample)

* Descriptive statistics
estpost sum price_incumbent_base price_incumbent_cheap cheapest_overall price_dispersion online_price_dispersion price_discrimination search_electricity search_gas net_costs purch num_hh hh_size,d
eststo desc

esttab desc using desc.tex,replace ///
refcat(price_incumbent_base "\textbf{Dependent variables}" ///
search_electricity "\addlinespace\textbf{Variables of interest}" ///
search_gas "\addlinespace\textbf{Instruments}" ///
net_costs "\addlinespace\textbf{Control variables}" ,nolabel) ///
collabels(\multicolumn{1}{c}{Mean} \multicolumn{1}{c}{SD} \multicolumn{1}{c}{Min} \multicolumn{1}{c}{Max} \multicolumn{1}{l}{Obs}) ///
substitute(\_ _) cells("mean(fmt(2)) sd(fmt(2)) min(fmt(2)) max(fmt(2))") ///
label nonumber nomtitles fragment booktabs stats(N, labels("Obs.") fmt(%9.0fc)) 

***************************
*	3. Estimations 
***************************

// Table 2

ivreghdfe log_price_incumbent_base $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv1

ivreghdfe log_price_incumbent_cheap $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv2

ivreghdfe log_cheapest_overall $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv3

local numbers "& (1) & (2) & (3) \\ "
esttab iv1 iv2 iv3 using iv_1.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe F_eff estatp N, fmt(0 0 2 2 %9.0fc) ///
labels("Year FE" "Zip code FE" "First stage effective F stat."  "Durbin-Wu-Hausman test" "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
order(log_search_electricity) nogap

// Table 3

ivreghdfe log_price_dispersion $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv4

ivreghdfe log_price_discrimination $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv5

ivreghdfe log_online_price_dispersion $price_controls (log_search_electricity= $instr),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv6

local numbers "& (1) & (2) & (3) \\ "
esttab iv4 iv5 iv6 using iv_2.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe F_eff estatp N, fmt(0 0 2 2 %9.0fc) ///
labels("Year FE" "Zip code FE" "First stage effective F stat." "Durbin-Wu-Hausman test" "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
order(log_search_electricity) nogap


***********************
* 	Appendix Tables
***********************

// Table B1

ivreghdfe search_electricity   (price_incumbent_base=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo search_pinc

ivreghdfe search_electricity   (price_incumbent_cheap=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo search_cinc

ivreghdfe search_electricity   (cheapest_overall=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo search_pent

ivreghdfe search_gas   (price_incumbent_base=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo gas_pinc

ivreghdfe search_gas (price_incumbent_cheap=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo gas_cinc

ivreghdfe search_gas  (cheapest_overall=net_costs),  absorb(plz year) cluster(plz)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo gas_pent

local numbers "& (1) & (2) & (3) & (4) & (5) & (6) \\ "

esttab search_pinc search_cinc search_pent gas_pinc gas_cinc gas_pent using search_gas.tex, replace ///
se order(price_inc cheapest_gv price_ent) star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe widstat N, fmt(0 0 2 %9.0fc) ///
labels("Year FE" "Zip code FE" "First stage F stat."  "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.3f) se(%9.3f) noabbrev fragment ///
mgroups("Electricity searches" "Gas searches", pattern(1 0 0 1 0 0 0) ///
prefix(\multicolumn{@span}{c}{) suffix(}) span ///
erepeat(\cmidrule(lr){@span})) nomtitle  ///
nonumbers nogap

// Table B2

xtsum price_incumbent_base price_incumbent_cheap cheapest_overall price_dispersion price_discrimination online_price_dispersion search_electricity search_gas net_costs


// Table B3

ivreghdfe log_search_electricity log_search_gas,  absorb (plz year)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo fs_nocov

ivreghdfe log_search_electricity log_search_gas $price_controls,  absorb(plz year)
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo fs

local numbers "& (1) & (2) \\ "

esttab fs_nocov fs using fs.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe N, fmt(0 0 %9.0fc) ///
labels("Year FE" "Zip code FE" "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
nonumbers nogap

// Table B4

ivreghdfe log_price_incumbent_base $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols1

ivreghdfe log_price_incumbent_cheap $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols2

ivreghdfe log_cheapest_overall $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols3

local numbers "& (1) & (2) & (3) \\ "
esttab ols1 ols2 ols3 using ols_1.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe N, fmt(0 0 %9.0fc) ///
labels("Year FE" "Zip code FE" "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
order(log_search_electricity) nogap

// Table B5

ivreghdfe log_price_dispersion $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols4

ivreghdfe log_price_discrimination $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols5

ivreghdfe log_online_price_dispersion $price_controls log_search_electricity, $options_ols
estadd local yfe "Yes"
estadd local rfe "Yes"
eststo ols6

local numbers "& (1) & (2) & (3) \\ "
esttab ols4 ols5 ols6 using ols_2.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe N, fmt(0 0 %9.0fc) ///
labels("Year FE" "Zip code FE" "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
nonumbers order(log_search_electricity) nogap


// Table B6

ivreghdfe log_price_incumbent_base $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv1_hausman

ivreghdfe log_incumbent_cheapest $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv2_hausman

ivreghdfe log_cheapest_overall $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv3_hausman

local numbers "& (1) & (2) & (3)  \\ "

esttab iv1_hausman  iv2_hausman  iv3_hausman using iv1_hausman.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe F_eff N, fmt(0 0 2 %9.0fc) ///
labels("Year FE" "Zip code FE" "First stage effective F stat." "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
nonumbers order(log_search_electricity) nogap

// Table B7

ivreghdfe log_price_dispersion $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv4_hausman

ivreghdfe log_price_discrimination $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv5_hausman


ivreghdfe log_online_price_dispersion $price_controls (log_search_electricity= log_search_gas_haus),  $options_iv
estadd local yfe "Yes"
estadd local rfe "Yes"
estadd scalar F_eff
eststo iv6_hausman

local numbers "& (1) & (2) & (3)  \\ "

esttab iv4_hausman  iv5_hausman  iv6_hausman using iv2_hausman.tex, replace ///
se star(* 0.10 ** 0.05 *** 0.01) ///
stats(yfe rfe F_eff N, fmt(0 0 2 %9.0fc) ///
labels("Year FE" "Zip code FE" "First stage effective F stat." "Obs." )) /// 
noline booktabs posthead("`numbers'"\midrule) prefoot(\midrule) ///
label substitute(\_ _) b(%9.4f) se(%9.4f) noabbrev fragment ///
nonumbers order(log_search_electricity) nogap

exit
